/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.giftmemo.ui.view;

import com.alee.extended.panel.AccordionListener;
import com.alee.extended.panel.AccordionStyle;
import com.alee.extended.panel.WebAccordion;
import com.alee.laf.scroll.WebScrollPane;
import com.giftmemo.objects.Person;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

/**
 *
 * @author Egor
 */
public class ViewFriendsPanel extends JPanel {
private WebScrollPane container;
private WebAccordion accordion;
    public ViewFriendsPanel() {
        accordion  = new WebAccordion(AccordionStyle.separated);
        init();
    }

    private void init() {
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  
        accordion.addAccordionListener(new AccordionListener() {

            @Override
            public void selectionChanged() { 
               
            }
        });
        
        add(accordion);
    }

    public void setFrindsList(List<Person> frineds) {
        List<PersonInfoPanel> uiComponents = convertPersonObjectsListToUIComponents(frineds);
        for (PersonInfoPanel component : uiComponents) {
            accordion.addPane("", component);
            
        }
        
    }

    private List<PersonInfoPanel> convertPersonObjectsListToUIComponents(List<Person> frineds) {
        List<PersonInfoPanel> components = new ArrayList<>(frineds.size());
        for (Person persn : frineds) {
            PersonInfoPanel infoPanel = new PersonInfoPanel();
            infoPanel.setAddGiftAction(new AbstractAction("Add gift") {
                
                @Override
                public void actionPerformed(ActionEvent e) {
                
                
                }
            });
            
            infoPanel.setPerson(persn);
            components.add(infoPanel);
            infoPanel = null; //help GC
        }
        return components;
    }

}
